//
//  luodaiClothingTypeViewController.m
//  LeaClothing
//
//  Created by LeaClothing on 2019/8/2.
//  Copyright © 2019年 LeaClothing. All rights reserved.
//

#import "luodaiClothingTypeViewController.h"

@interface luodaiClothingTypeViewController ()<LeaClothingBasicImageViewDelegate>

@property (weak, nonatomic) IBOutlet LeaClothingBasicImageView *clothingPhotoImageView;
@property (weak, nonatomic) IBOutlet UITextField *clothingTypeTF;
@property (weak, nonatomic) IBOutlet UITextField *styleQuantityTF;
@property (weak, nonatomic) IBOutlet UINavigationItem *addClothingViewNavitem;
@property (weak, nonatomic) IBOutlet UILabel *clothingTypeDescLab;
@property (weak, nonatomic) IBOutlet UILabel *styleQuantityDescLab;
@property (weak, nonatomic) IBOutlet UILabel *styleQuantiyUnitLab;

@property (nonatomic, strong) UIImage *clothingPhotoImg;

@end

@implementation luodaiClothingTypeViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    if (self.type==AddClothingType_series) {
        self.addClothingViewNavitem.title = self.clothingTypeName;
        self.clothingTypeDescLab.text = @"Clothing name";
        self.styleQuantityDescLab.text = @"Clothing price";
        self.clothingTypeTF.placeholder = @"enter clothing name";
        self.styleQuantityTF.placeholder = @"enter clothing price";
        self.styleQuantityTF.enabled = YES;
        self.styleQuantityTF.text = @"";
        self.styleQuantiyUnitLab.text = @"$";
    }
     self.clothingPhotoImageView.delegate = self;
}

- (void)leaClothingBasicImageView:(LeaClothingBasicImageView *)imageView didSelectImage:(UIImage *)image{
    self.clothingPhotoImg = image;
    self.clothingPhotoImageView.image = image;
}

- (IBAction)addClothingTypeViewSureAction:(id)sender {
    BOOL isClothingTypeView = self.type== AddClothingType_type;
    if (!self.clothingPhotoImg) {
        kShowAlertWithMsg(@"Please add clothing photo");
        return;
    }
    if (_clothingTypeTF.text.length==0) {
        kShowAlertWithMsg(kFormat(@"Please enter %@",isClothingTypeView?@"clothing type":@"clothing price"));
        return;
    }
    if (_styleQuantityTF.text.length==0) {
        kShowAlertWithMsg(kFormat(@"Please enter %@",isClothingTypeView?@"style quantity":@"clothing quantity"));
        return;
    }
    if (isClothingTypeView) {
        ClothingInfoModel *clothingModel = [ClothingInfoModel new];
        clothingModel.clothingTypeImg = _clothingPhotoImg;
        clothingModel.clothingTypeName = _clothingTypeTF.text;
        clothingModel.clothingTypePrice = _styleQuantityTF.text;
        clothingModel.bg_tableName = clothing_tablename;
        [clothingModel bg_save];
        [[NSNotificationCenter defaultCenter] postNotificationName:ClothingWarehouseViewRefresh object:nil];
    }else{
        ClothingSeriesModel *seriesModel = [ClothingSeriesModel new];
        seriesModel.seriesImg = _clothingPhotoImg;
        seriesModel.seriesName = _clothingTypeTF.text;
        seriesModel.seriesPrice = _styleQuantityTF.text;
        !self.addClothingSeriesSureBlock?:self.addClothingSeriesSureBlock(seriesModel);
    }
    [self.navigationController popViewControllerAnimated:YES];
    
}
- (IBAction)addClothingTypeTapAction:(id)sender {
    [self.view endEditing:YES];
}


@end
